﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Helena.Models;

namespace Helena.Areas.Campanas.Models
{
    public class LogicaCampana:InterfazLogicaCampana
    {
        DBContext Campana_contexto = new DBContext();
        DBGenericQueriesUtil<Campana> Tabla;

        public DBContext context_publico { get { return Campana_contexto; } }

        public LogicaCampana()
        {
            Tabla = new DBGenericQueriesUtil<Campana>(Campana_contexto,Campana_contexto.t_Campanas);
        }

        public void i_AgregarCampana(CampanaView c_v)
        {
            Tabla.agregarElemento(c_v.deserializa(this));
        }

        public void i_ModificarCampana(CampanaView c_v)
        {
            Campana c = c_v.deserializa(this);
            Tabla.modificarElemento(c, c.ID);
        }

        public void i_EliminarCampana(int id)
        {
            Tabla.eliminarElemento_logico(id);
        }

        public List<CampanaView> i_RetornarCampanas()
        {
            List<Campana> c = Tabla.retornarTodos();
            List<CampanaView> c_v = new List<CampanaView>();

            foreach (Campana campana in c) c_v.Add(new CampanaView(campana));
            return c_v;
        }

        public CampanaView i_RetornarCampana(int id)
        {
            Campana c = Tabla.retornarUnSoloElemento(id);
            CampanaView c_v = new CampanaView(c);
            return c_v;
        }
    }
}